<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:general="http://java.sun.com/jsf/composite/components/general">

    <ui:composition template="template.xhtml">
        <ui:define name="dialogs">

             <general:confirmDialog
                widgetDialog="confirmRemoveDialog"
                dialogTitle="Remoção de marca"
                message="Deseja remover a marca selecionado?"
                buttonYesAction="#{marcaBean.delete()}"
                onclick_no_javascript="confirmRemoveDialog.hide()"
                onclick_yes_javascript="confirmRemoveDialog.hide()"
                onclick_yes_update=":growl :marcaForm"/>

            <p:dialog header="Cadastro de marca" widgetVar="newMarca" modal="true" resizable="false">
                <p:panel id="panelDetalhe" header="Marca" style="width: 310px">

                    <h:form id="newMarcaform">
                          <h:panelGrid columns="2">
                            <h:outputText value="Nome: "  />
                            <p:inputText value="#{marcaBean.marca.name}"  style="width: 170px"/>

                          </h:panelGrid>
                        <p:separator />
                        <p:commandButton value="Salvar" action="#{marcaBean.save()}" update=":marcaForm :growl" onclick="newDetalhe.hide()" />
                    </h:form>

                </p:panel>
            </p:dialog>

        </ui:define>



        <ui:define name="content">
            <h:form id="marcaForm">
              <h:panelGrid columns="2">
                        <h:outputText value="Nome:" styleClass="formLabel" style="width: 120px"/>
                        <p:inputText id="marcaName" style="width: 300px" value="#{marcaBean.marcaNameFilter}"
                                     onclick="jQuery(this).select()">
                            <p:ajax event="keyup" update="marcaList" />
                        </p:inputText>

                        <p:watermark for="marcaName" value="Digite o nome da marca" />
                    </h:panelGrid>
              <h:panelGroup id="marcaList">
                  <p:dataTable var="m" value="#{marcaBean.listMarcas()}"
                               paginator="true" rows="10" rowKey="#{m.id}"
                                     emptyMessage="Nenhuma marca foi encontrado"
                                     selectionMode="single" selection="#{marcaBean.marcaSelected}">

                            <p:ajax event="rowSelect" update="@this"/>

                            <f:facet name="header">
                                Lista de marcas
                            </f:facet>

                            <p:column style="width: 70%">
                                <f:facet name="header">
                                    <h:outputText value="Nome" />
                                </f:facet>
                                <h:outputText value="#{m.name}" />
                            </p:column>


                            <f:facet name="footer">
                                <p:commandButton icon="ui-icon ui-icon-plus" title="Adicionar marca" update=":newMarcaform" oncomplete="newMarca.show()"
                                                 disabled="#{not sharedPermissionManagedBean.hasPermission('CRIAR_MARCA_PRODUTO')}"/>
                                <p:commandButton icon="ui-icon ui-icon-pencil" title="Editar marca" 
                                                 disabled="#{(not sharedPermissionManagedBean.hasPermission('EDITAR_MARCA_PRODUTO')) or (marcaBean.marcaSelected.id == null)}"/>

                                <p:commandButton icon="ui-icon ui-icon-minus" title="Remover marca" onclick="confirmRemoveDialog.show()"
                                                 disabled="#{(not sharedPermissionManagedBean.hasPermission('REMOVER_MARCA_PRODUTO')) or (marcaBean.marcaSelected.id == null)}"/>

                            </f:facet>
                        </p:dataTable>
                    </h:panelGroup>
            </h:form>
        </ui:define>
    </ui:composition>
</html>


